package com.cndongtai.util;

import java.util.regex.Pattern;

public class ValidateUtil {
	
	public static final String MOBILE_REG = "^1(3\\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$";
	
	public static final String EMAIL_REG = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

	
	public static boolean empty(String str) {
		if(null==str || "".equals(str)) {
			return true;
		}
		
		return false;
	}
	
	public static boolean notEmpty(String str) {
		if(null!=str && !"".equals(str)) {
			return true;
		}
		
		return false;
	}
	
	public static boolean checkMobile(String mobile) {
		return Pattern.matches(MOBILE_REG, mobile);
	}
	
	public static boolean checkEmail(String email) {
		return Pattern.matches(EMAIL_REG, email);
	}

	
	public static boolean checkImageFileExt(String fileName) {
		String fileNameLowerCase = fileName.toLowerCase() ;
		if(fileNameLowerCase.endsWith(".png") 
				|| fileNameLowerCase.endsWith(".jpg") 
				|| fileNameLowerCase.endsWith(".gif") 
				|| fileNameLowerCase.endsWith(".jepg")
				|| fileNameLowerCase.endsWith(".bmp")
				|| fileNameLowerCase.endsWith(".jpeg")){
			return true ;
		}else{
			return false ;
		}
	}
	
	public static boolean checkFirmwareFileExt(String fileName) {
		String fileNameLowerCase = fileName.toLowerCase() ;
		if(fileNameLowerCase.endsWith(".bin")){
			return true ;
		}else{
			return false ;
		}
	}

}
